import java.util.Arrays;

public class TestDemo {

    public static void main(String[] args) {

    }

    public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; ++i) {
            boolean flg = false;
            for (int j = 0; j < array.length - 1 - i; ++j) {
                if (array[j] > array[j + 1]) {
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flg = true;
                }
            }
            if (!flg) {
                break;
            }
        }
    }

    public static void main_04(String[] args) {
        int[] array1=new int[] {1,2,3,4,5,6};
        int[] array2=new int[array1.length];
        for(int i=0;i<array1.length;++i){
            array2[i]=array1[i];
        }
        System.out.println(Arrays.toString(array2));
        int[] array3=Arrays.copyOf(array1,array1.length);
        System.out.println(Arrays.toString(array3));
        //int[] array3 = Arrays.copyOfRange(array1, 1, 3);
        int[] array4 = new int[array1.length];
        System.arraycopy(array1, 0, array4, 0, array1.length);
        System.out.println(Arrays.toString(array4));
        int[] array5 = (int[])array1.clone();
        System.out.println(Arrays.toString(array5));
    }

    public static int fib1(int n){
        if(n==1||n==2){
            return 1;
        }
        return fib1(n-1)+fib1(n-2);
    }
    public static int fib2(int n){
        int a[] = new int[n+1];
        a[0]=0;
        a[1]=1;
        for(int i=2;i<=n;i++){
            a[i] = a[i-1]+a[i-2];
        }
        return a[n];
    }

    public static void main_03(String[] args) {
        int n=fib2(10);
        System.out.println(n);
    }

    public static int[] fib(int n){
        if(n <= 0){
            return null;
        }
        int[] array = new int[n];
        array[0] = array[1] = 1;
        for(int i = 2; i < n; ++i){
            array[i] = array[i-1] + array[i-2];
        }
        return array;
    }
    public static void main_02(String[] args) {
        int[] array = fib(10);
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }

    public static void main_01(String[] args) {
        int[] arr = {1, 2, 3};
        func(arr);
        System.out.println("arr[0] = " + arr[0]);
    }
    public static void func(int[] a) {
        a[0] = 10;
        System.out.println("a[0] = " + a[0]);
    }
}
